package com.wbao.dianniu.adapter;

import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wbao.dianniu.R;
import com.wbao.dianniu.data.RecReceiveData;
import com.wbao.dianniu.utils.PictureDownloadUtils;

public class RecReceiveAdapter extends BaseAdapter {

	private LayoutInflater mInflater;
	private List<RecReceiveData> mList;
	private Context mContext;
	
	public RecReceiveAdapter(Context context) {
		mContext = context;
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		if(null == mList){
			mList = new ArrayList<RecReceiveData>();
		}
	}
	
//	public void setData(List<RecReceiveData> list) {
//		mList = list;
//	}
	
	public void addData(List<RecReceiveData> list){
		if(null == mList){
			mList = new ArrayList<RecReceiveData>();
		}
		for (int i = 0; i < list.size(); i++) {
			mList.add(list.get(i));
		}
	}
	public List<RecReceiveData> getList() {
		return mList;
	}
	public void clear(){
		mList.clear();
		notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		if (null == mList)
			return 0;
		else
			return mList.size();
	}

	@Override
	public Object getItem(int position) {
		return mList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		GridHolder holder;
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.receive_job_item, null);   
			holder = new GridHolder();
			holder.headIV = (ImageView)convertView.findViewById(R.id.user_head);
			holder.name = (TextView)convertView.findViewById(R.id.user_name);
			holder.label = (TextView)convertView.findViewById(R.id.user_label);
			holder.createDate = (TextView)convertView.findViewById(R.id.user_date);
			holder.sex = (TextView)convertView.findViewById(R.id.receive_job_sex);
			holder.educationTV =  (TextView)convertView.findViewById(R.id.receive_job_education);
			holder.experienceTV =  (TextView)convertView.findViewById(R.id.receive_job_experience);
			holder.postTV = (TextView) convertView.findViewById(R.id.receive_job_post);
			holder.salaryTV =  (TextView)convertView.findViewById(R.id.receive_job_salary);
			convertView.setTag(holder); 
		}else{
			holder = (GridHolder) convertView.getTag();
		}
		
		RecReceiveData data = mList.get(position);
		if(null != data){
			PictureDownloadUtils.displayHeadImage(mContext,holder.headIV, data.getHeadPic());
			holder.name.setText(data.getRealName() == null ? "": data.getRealName());
			holder.label.setText(data.getLabel() == null ? "": data.getLabel());
			holder.createDate.setText(data.getCreateDate() == null ? "": data.getCreateDate());
			holder.createDate.setVisibility(View.VISIBLE);
			holder.sex.setText(data.getSexDesc()==null ? "" : "" + data.getSexDesc());
			holder.experienceTV.setText(data.getExperience()==null ? "" : "" + data.getExperience());
			holder.educationTV.setText(data.getEducation() == null ? "":"" + data.getEducation());
			holder.postTV.setText(data.getPost()  == null ? "": "应聘：" + data.getPost());
			holder.salaryTV.setText(data.getSalary() == null ? "":data.getSalary());
		}
		
		return convertView;
	}
	
	private class GridHolder {
		public ImageView headIV;
		public TextView name;
		public TextView label;
		private TextView createDate;
		public TextView sex;
		public TextView experienceTV;
		public TextView educationTV;
		public TextView postTV;
		public TextView salaryTV;
	}

}
